﻿using System;
using System.Text;

namespace WTM.Lutools.ViewModel.Helper;

public class JwtTokenHelper
{
    public static string JwtTokenDecode(string token)
    {
        var split = token.Split('.');
        var payload = split[1];

        var padded = payload.Length % 4 == 0
            ? payload
            : payload + "====".Substring(payload.Length % 4);
        var base64 = padded.Replace("_", "/")
            .Replace("-", "+");

        var outputb = Convert.FromBase64String(base64);
        var orgStr = Encoding.Default.GetString(outputb);
        return orgStr;
    }
}